<?

class Admin_Login_Controller extends Base_Controller {

   
    public function action_index()
    {   
        if(Session::get('username')){
            return Redirect::to('/admin/index/index');
        }else{   
            return View::make('admin.login');    
       }
    }


     public function action_logout()
    {   
        Session::forget('username');
        Session::forget('code');
        //return View::make('jump.error2',array('msg'=>'退出成功','time'=>3,'url'=>'login'));
         return Redirect::to('/admin/login/index');
    }


      public function action_dologin()
    {   
        $username = Input::get('username');
        $password = Input::get('password');
        $user = DB::table('users_admin')->where('username','=',$username)->where('password','=',$password)->first();
        $code = $user['code'];
        if($user){
            $username = Session::put('username',$username);
            $code = Session::put('code',$code);
            return Redirect::to('admin/index/index');
        }else{
            $warnings[] = '该用户或密码错误';
            return View::make('admin.login', array('warnings' => $warnings));
        }  
    }




}